package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.awt.FlowLayout;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class ComponentInWindow extends JFrame{ //JFrame是底层容器
	
	private static final long serialVersionUID = -4933808674595075440L;
	JTextField text;
	JButton button;
	JCheckBox checkBox1, checkBox2, checkBox3;
	ButtonGroup group;
	JRadioButton radio1, radio2;
	JComboBox<String> comboBox;
	JTextArea area;
	
	public ComponentInWindow() {
		init();
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	void init() {
		setLayout(new FlowLayout()); //设置Flow布局
		add(new JLabel("文本框")); //标签信息
		text = new JTextField(10); //文本框的长度
		add(text);
		add(new JLabel("按钮")); 
		button = new JButton("确定"); //按钮
		add(button);
		add(new JLabel("选择框："));
		checkBox1 = new JCheckBox("喜欢音乐"); //复选按钮
		checkBox2 = new JCheckBox("喜欢旅游");
		checkBox3 = new JCheckBox("喜欢篮球");
		add(checkBox1);
		add(checkBox2);
		add(checkBox3);
		add(new JLabel("单选按钮"));
		group = new ButtonGroup(); //按钮集合
		radio1 = new JRadioButton("男"); //单选按钮
		radio2 = new JRadioButton("女");
		group.add(radio1);
		group.add(radio2);
		add(radio1);
		add(radio2);
		add(new JLabel("下拉列表："));
		comboBox = new JComboBox<String>(); //下拉列表
		comboBox.addItem("音乐天地"); //列表项
		comboBox.addItem("音乐天地");
		comboBox.addItem("音乐天地");
		add(comboBox);
		add(new JLabel("文本区"));
		area = new JTextArea(6, 12); //文本区
		add(new JScrollPane(area)); //JScrollPane滚动挑容器
	}
	
}
